package com.zzptc.fxh.myapplication;

import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;

import java.util.ArrayList;
import java.util.List;

public class SecondFragment extends Fragment {

    public SecondFragment() {
    }
    // TODO: Rename and change types and number of parameters
    public static SecondFragment newInstance(String param1, String param2) {
        SecondFragment fragment = new SecondFragment();
        Bundle args = new Bundle();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_second, container, false);
        BarChart bar = view.findViewById(R.id.barChart);
        List<BarEntry> data=new ArrayList<>();

        data.add(new BarEntry(1,8));
        data.add(new BarEntry(2,6));
        data.add(new BarEntry(3,3));
        data.add(new BarEntry(4,4));
        data.add(new BarEntry(5,1));
        BarDataSet DataSet = new BarDataSet(data, "");
        DataSet.setColor(Color.RED);

        List<BarEntry> data1=new ArrayList<>();
        data1.add(new BarEntry(1,2));
        data1.add(new BarEntry(2,5));
        data1.add(new BarEntry(3,6));
        data1.add(new BarEntry(4,1));
        data1.add(new BarEntry(5,7));
        BarDataSet DataSet1 = new BarDataSet(data1, "");
        DataSet1.setColor(Color.YELLOW);

        BarData barData=new BarData();
        barData.addDataSet(DataSet);
        barData.addDataSet(DataSet1);

        bar.setData(barData);

        bar.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
        bar.getAxisRight().setEnabled(false);
        bar.getDescription().setEnabled(false);
        barData.groupBars(1,0.3f,0);
        bar.getXAxis().setAxisMaximum(11);
        bar.getXAxis().setAxisMinimum(1);
        bar.getXAxis().setLabelCount(5,false);
        bar.getXAxis().setCenterAxisLabels(true);
        return view;
    }
}
